{% extends 'backstage/root/manage_competition/base.html' %}
{% from 'bootstrap/pagination.html' import render_pagination %}

{% block competition_content %}
    <h4>
        Competitions
        <small class="text-muted">{{ pagination.total|default(0) }}</small>
    </h4>

    <div>
        <div class="table-responsive">
            <table class="table table-striped table-hover table-sm">
                <thead>
                <tr class="text-center">
                    <th>#</th>
                    <th>{{ _("Competition name") }}</th>
                    <th>{{ _("Date") }}</th>
                    <th>{{ _("Actions") }}</th>
                </tr>
                </thead>
                {% for com in pagination.items %}
                    <tr>
                        <td class="text-center">
                            {{ pagination.total - (config['COMPETITION_PER_PAGE'] * (page - 1) + loop.index) + 1 }}
                        </td>
                        <td class="text-center">{{ com.name }}</td>
                        <td class="text-center">{{ com.date }}</td>
                        <td class="text-center">
                            <div class="btn-group dropleft">
                                <button class="btn btn-sm btn-info dropdown-toggle" type="button"
                                        id="dropdownMenuButton"
                                        data-toggle="dropdown" aria-haspopup="true" aria-expanded="false">
                                    <span class="oi oi-cloud-download"></span> {{ _("Download") }}
                                </button>
                                <div class="dropdown-menu" aria-labelledby="dropdownMenuButton">
                                    <form role="form"
                                          action="{{ url_for('root.download_teacher', competition_id=com.id) }}"
                                          method="post">
                                        <input type="hidden" id="csrf_token" name="csrf_token"
                                               value="{{ csrf_token() }}"/>
                                        <button class="dropdown-item">
                                            <span class="oi oi-data-transfer-download"></span> {{ _("Download all teachers result") }}
                                        </button>
                                    </form>
                                    <form role="form"
                                          action="{{ url_for('root.download_teacher', competition_id=com.id) }}"
                                          method="post">
                                        <input type="hidden" id="csrf_token" name="csrf_token"
                                               value="{{ csrf_token() }}"/>
                                        <button class="dropdown-item">
                                            <span class="oi oi-data-transfer-download"></span> {{ _("Download the final result") }}
                                        </button>
                                    </form>
                                </div>
                            </div>
                        </td>
                    </tr>
                {% endfor %}
            </table>
        </div>
        <div class="page-footer">
            {{ render_pagination(pagination) }}
        </div>
    </div>
{% endblock %}
